// MainDlg.h : interface of the CMainDlg class
//
/////////////////////////////////////////////////////////////////////////////

#pragma once

#include "LitePlayer.h"
#include "MediaProp.h"

#include <string>
#include <atlstr.h>
#include <atlpath.h>
#include <atlctrlx.h>
#include <atlcrack.h>


class CMainDlg : public CDialogImpl<CMainDlg>, public CUpdateUI<CMainDlg>,
		public CMessageFilter, public CIdleHandler
{
public:
	enum { IDD = IDD_MAINDLG };

	virtual BOOL PreTranslateMessage(MSG* pMsg);
	virtual BOOL OnIdle();

	BEGIN_UPDATE_UI_MAP(CMainDlg)
	END_UPDATE_UI_MAP()

	BEGIN_MSG_MAP(CMainDlg)
        
		MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
		MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
		COMMAND_ID_HANDLER(ID_APP_ABOUT, OnAppAbout)
		COMMAND_ID_HANDLER(IDOK, OnOK)
		COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
        COMMAND_ID_HANDLER(ID_FILE_OPEN, OnFileOpen)
        COMMAND_ID_HANDLER(ID_FILE_CLOSE, OnFileClose)
        COMMAND_ID_HANDLER(ID_FILE_OPEN_URL, OnFileOpenUrl)
        COMMAND_ID_HANDLER(ID_PLAY, OnBnClickedPlay)
        COMMAND_ID_HANDLER(ID_STOP, OnBnClickedStop)
        COMMAND_ID_HANDLER(ID_SLOW, OnBnClickedSlow)
        COMMAND_ID_HANDLER(ID_FAST, OnBnClickedFast)
        COMMAND_ID_HANDLER(ID_FULLSCREEN, OnBnClickedFullscreen)
        COMMAND_ID_HANDLER(ID_SNAP, OnSnap)
        COMMAND_ID_HANDLER(ID_FILE_OPEN_URL, OnFileOpenUrl)
        COMMAND_ID_HANDLER(ID_CONTROL, OnControl)
        COMMAND_ID_HANDLER(ID_VOLUME_INC, OnVolumeInc)
        COMMAND_ID_HANDLER(ID_VOLUME_DEC, OnVolumeDec)
        COMMAND_ID_HANDLER(ID_MUTE, OnVolumeMute)
        COMMAND_ID_HANDLER(ID_RATIO_FIT, OnRatioFit)
        COMMAND_ID_HANDLER(ID_RATIO_DEFAULT, OnRatioDefault)
        COMMAND_ID_HANDLER(ID_RATIO_1V1, OnRatio1V1)
        COMMAND_ID_HANDLER(ID_RATIO_16V9, OnRatio16V9)
        COMMAND_ID_HANDLER(ID_RATIO_4V3, OnRatio4V3)

    
        MSG_WM_SIZE(OnSize)
        MSG_WM_ERASEBKGND(OnEraseBkgnd)
        MSG_WM_DROPFILES(OnDropFiles)
        MSG_WM_KEYDOWN(OnKeyDown)

	END_MSG_MAP()

// Handler prototypes (uncomment arguments if needed):
//	LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
//	LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
//	LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)

	LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
	LRESULT OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
	LRESULT OnAppAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnOK(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);

	void CloseDialog(int nVal);

    
public:
    av::LitePlayer*    m_player;

    void init();
    void uninit();

    bool isOpen();

    bool openFile(const CString& filepath);
    void closeFile();
    void play();
    void pause();
    void stop();

    void onPlayerOpenClose(bool opened);
    void onPlayerPause(bool paused);

    CString chooseFile();

    std::string getSnapDir();

private:
    CString m_url;

public:
    LRESULT OnFileOpen(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    LRESULT OnFileClose(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    LRESULT OnBnClickedPlay(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    LRESULT OnBnClickedPause(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    LRESULT OnBnClickedStop(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    LRESULT OnBnClickedSlow(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    LRESULT OnBnClickedFast(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    LRESULT OnBnClickedFullscreen(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    LRESULT OnSnap(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    LRESULT OnFileOpenUrl(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    LRESULT OnControl(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);

    LRESULT OnVolumeDec(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    LRESULT OnVolumeInc(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    LRESULT OnVolumeMute(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);

    LRESULT OnRatioFit(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    LRESULT OnRatioDefault(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    LRESULT OnRatio1V1(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    LRESULT OnRatio16V9(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    LRESULT OnRatio4V3(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);

    void OnSize(UINT nType, const CSize& size);

    BOOL OnEraseBkgnd(HDC hdc);

    void OnDropFiles(HDROP hDrop);

    void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);

};
